/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package justdoit.view;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author shadone
 */
public class ProgressBarRenderer extends JSlider implements TableCellRenderer {

    public ProgressBarRenderer() {
        super(0, 100);
    }

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        int val = ((Integer) value).intValue();
        setValue(val);

        // Needed to properly paint the slider.
        updateUI();

        if (val < 33)
            this.setBackground(Color.red);
        else if (val<66)
            this.setBackground(Color.yellow);
        else if (val<100)
            this.setBackground(Color.green);

        return this;
    }
}
